DEMO: How do if, elif, and else work together?

An if statement is always tested.

An elif statement is only tested if the if statement above it was False.

An else code block only runs if both the if statement and the elif statement were False.

  • Click Run to see the if-elif-else logic. Run it again and enter a different answer!

To navigate the page using the TAB key, first press ESC to exit the code editor.

# THIS ACTIVITY IS IN PREVIEW ONLY MODE
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)